package com.donn.securitycontrolplatform.equipment.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.donn.securitycontrolplatform.common.Result;
import com.donn.securitycontrolplatform.equipment.entity.TGroup;
import com.donn.securitycontrolplatform.equipment.service.ITGroupService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhenglx
 * @since 2022-06-19
 */
@RestController
@RequestMapping("/scp/api/group")
@Tag(name = "Group-controller", description = "设备分组controller")

public class TGroupController {

    @Autowired
    ITGroupService service;

    @ApiOperation(value = "新增分组")
    @PostMapping("/add")
    @ResponseBody
    public Result add(@ApiParam @RequestBody TGroup group) {
        return service.insertGroup(group);
    }

    @ApiOperation(value = "修改组信息")
    @PutMapping("/update")
    @ResponseBody
    public Result update(@RequestBody TGroup group) {
        return service.updateGroup(group);
    }

    @ApiOperation(value = "删除设备组")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "组id")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public Result delete(@RequestParam String groupId) {
        return service.deleteGroup(groupId);
    }

    @ApiOperation(value = "查询列表")
    @GetMapping("/list")
    @ResponseBody
    public Result list(@ApiIgnore TGroup group, Page page) {
        return service.selectGroupList(group, page);
    }

    @ApiOperation(value = "组详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "组id")
    })
    @GetMapping("/get")
    @ResponseBody
    public Result get(@RequestParam String groupId) {
        return service.getGroupById(groupId);
    }

}
